package com.lazydong.gui_gateway.gui;

import cn.hutool.core.date.LocalDateTimeUtil;
import com.lazydong.gui_gateway.model.ServiceIpAddr;

import javax.swing.*;
import java.time.LocalDateTime;

public class LogUtil {
    public static JTextArea logTextArea;

    public static void appendLog(String log) {
        logTextArea.append(log);
        logTextArea.append(System.lineSeparator());
    }

    public static void addRouteLog(ServiceIpAddr serviceIpAddr) {
        String str = getTime() + " 添加 "+serviceIpAddr.getServiceName()+" 路由";
        logTextArea.append(str);
        logTextArea.append(System.lineSeparator());
    }
    public static void updateRouteLog(ServiceIpAddr serviceIpAddr) {
        if (serviceIpAddr.getServiceId().equals("environment")) {
            return;
        }
        String str = getTime() + " 更新 "+serviceIpAddr.getServiceName()+" 路由";
        logTextArea.append(str);
        logTextArea.append(System.lineSeparator());
    }
    public static void deleteRouteLog(ServiceIpAddr serviceIpAddr) {
        String str = getTime() + " 移除 "+serviceIpAddr.getServiceName()+" 路由";
        logTextArea.append(str);
        logTextArea.append(System.lineSeparator());
    }

    private static String getTime() {
        return LocalDateTimeUtil.format(LocalDateTime.now(), "HH:mm:ss");
    }
}
